1 00:00:00,500 --> 00:00:03,090 Now I want to do my server side stuff. 2 00:00:03,110 --> 00:00:08,150 I'm going to make this window invisible so I don't have so I don't have it in my way. 3 00:00:08,180 --> 00:00:13,130 Let's go to shop frame and then we'll say visible uncheck. 4 00:00:13,610 --> 00:00:15,950 Let's go to server script service. 5 00:00:16,400 --> 00:00:17,340 There it is. 6 00:00:17,380 --> 00:00:18,430 Let's closed up. 7 00:00:18,440 --> 00:00:26,540 And I want to get this prop test, property test, and I'm going to disable that so it doesn't run. 8 00:00:26,540 --> 00:00:29,600 And then I'm going to open my property manager. 9 00:00:29,680 --> 00:00:35,870 I'm going to put some of that property test in the property manager when we make our purchase, let's 10 00:00:35,870 --> 00:00:42,950 scroll up to the top of our property manager and I need to add server storage because that's where we 11 00:00:42,950 --> 00:00:44,420 have our houses and stuff. 12 00:00:44,420 --> 00:00:55,070 So I'll do a local game, get service server storage, and then I also need another helper function. 13 00:00:55,070 --> 00:00:56,570 I'll just put it at the top. 14 00:00:56,720 --> 00:01:05,230 Let's do function prop, manage server and I'm going to call this get player lot. 15 00:01:05,260 --> 00:01:07,240 So this is going to pass in. 16 00:01:07,480 --> 00:01:13,330 We're going to pass in a player and it's going to tell you which lot that they're currently occupying 17 00:01:13,330 --> 00:01:14,710 while you're playing the game. 18 00:01:14,710 --> 00:01:19,690 Because remember, we we assign lots dynamically so it won't be the same one every time. 19 00:01:20,260 --> 00:01:21,570 Let's do an if statement. 20 00:01:21,580 --> 00:01:40,090 If property for the player exists and property for the player dot has lot, then the player owns a lot. 21 00:01:40,120 --> 00:01:43,420 Let's loop through the lot collection, find out which one they own. 22 00:01:43,420 --> 00:01:46,360 So we'll do for I and V in pairs. 23 00:01:46,690 --> 00:01:49,090 And we got a lot collection here. 24 00:01:50,050 --> 00:01:52,270 We'll do do. 25 00:01:52,910 --> 00:02:03,470 And we'll say if player equals equals v dot owner dot value, that's there a lot, then we're going 26 00:02:03,470 --> 00:02:08,690 to return V and V will be the lot that the player owns. 27 00:02:08,690 --> 00:02:10,550 So how are we going to use this? 28 00:02:10,550 --> 00:02:11,780 When are we going to use this? 29 00:02:11,810 --> 00:02:14,390 Scroll down a little bit underneath. 30 00:02:14,390 --> 00:02:20,750 I'm going to make another function, say local function prop manager. 31 00:02:21,080 --> 00:02:30,380 I'm going to call this one, add property item and the player is going to get passed in and the actual 32 00:02:30,380 --> 00:02:32,060 item is going to get passed in. 33 00:02:33,230 --> 00:02:34,610 Maybe scroll up a little more. 34 00:02:34,610 --> 00:02:39,500 So this one's this is the one that's going to mimic our property test script so much. 35 00:02:39,530 --> 00:02:42,350 First thing we're going to do, Oh, we already have server storage. 36 00:02:42,350 --> 00:02:48,620 I was going to get server storage, but we have it, so we'll do local item template. 37 00:02:48,620 --> 00:02:48,880 Right? 38 00:02:48,890 --> 00:02:50,510 We need the item template. 39 00:02:50,690 --> 00:02:58,260 If you remember that for our property test, we'll do server storage, wait for child, and then we 40 00:02:58,260 --> 00:02:59,970 got to get the item right. 41 00:02:59,970 --> 00:03:02,460 That's either going to be the cabin or the fence. 42 00:03:02,970 --> 00:03:04,500 We're going to pass it in dynamically. 43 00:03:04,500 --> 00:03:05,970 This will work for both of them. 44 00:03:06,090 --> 00:03:08,490 Then I want to clone that item. 45 00:03:08,490 --> 00:03:15,720 So I'm going to say item clone equals item temp, colon clone. 46 00:03:15,720 --> 00:03:23,820 We're going to make another copy and then we're going to get the lot to put the item on. 47 00:03:23,820 --> 00:03:29,760 So that's when we're going to use our prop manager module script function, right? 48 00:03:29,760 --> 00:03:31,560 So you have to prepend it with the table name. 49 00:03:31,560 --> 00:03:41,910 Even if you're inside the module script we'll do get was a get player lot pass in the player what else. 50 00:03:41,910 --> 00:03:50,280 Oh let's get the item clone and the parent is going to be the lot then remember we got that anchor thing 51 00:03:50,280 --> 00:03:50,700 right? 52 00:03:50,700 --> 00:03:53,930 So we'll say local anchor. 53 00:03:53,930 --> 00:04:00,440 This is the line up, the item we'll say Lot dot anchor Whoops, that's a capital lot. 54 00:04:00,470 --> 00:04:02,290 Dot anchor. 55 00:04:03,830 --> 00:04:05,000 Good. 56 00:04:05,150 --> 00:04:07,190 Now we're going to need our pivot. 57 00:04:07,460 --> 00:04:07,850 Right. 58 00:04:07,850 --> 00:04:15,020 We're going to get the the C frame of the anchor using that p PV instance base class. 59 00:04:15,020 --> 00:04:16,150 That's where it's at. 60 00:04:16,160 --> 00:04:17,600 You don't need to know that. 61 00:04:17,600 --> 00:04:21,890 We're just going to do anchor get pivot. 62 00:04:21,890 --> 00:04:29,750 That's going to give us a C frame on the anchor to line up our item with, and then we'll do the item 63 00:04:29,750 --> 00:04:36,170 clone, pivot to pivot to pass in the pivot. 64 00:04:36,920 --> 00:04:37,700 All right. 65 00:04:38,150 --> 00:04:40,820 Now you're probably thinking, where does this get called? 66 00:04:40,820 --> 00:04:45,470 Well, it's going to get called in a couple of places, but one of the places the first place that's 67 00:04:45,470 --> 00:04:49,280 going to get called is on the server side of our shop. 68 00:04:49,280 --> 00:04:53,240 So let's go to the shop, update that now. 69 00:04:53,240 --> 00:04:55,400 We're going to go to the bell. 70 00:04:55,400 --> 00:05:00,320 And that's where the the top of the bell I have the Activate shop script. 71 00:05:00,320 --> 00:05:02,150 Let's open that up. 72 00:05:03,040 --> 00:05:07,480 The reason I did that property manager stuff first is because we're going to need it. 73 00:05:07,900 --> 00:05:12,010 I'm going to get a variable for the property manager prop MGR. 74 00:05:12,190 --> 00:05:21,790 We are going to require that script game dot server Script service.property manager. 75 00:05:22,090 --> 00:05:29,440 Now remember, when we open it up, we're going to send data to our client so we can check to see if 76 00:05:29,440 --> 00:05:30,250 they have a lot. 77 00:05:30,280 --> 00:05:32,090 See if they already have the property. 78 00:05:32,110 --> 00:05:41,110 So I'm going to pass in that second value prop manager get player items to save. 79 00:05:41,110 --> 00:05:46,030 Let's let's use that one because that returns all the player items and we're just going to pass in a 80 00:05:46,030 --> 00:05:46,660 player. 81 00:05:46,670 --> 00:05:55,360 So on the on the client side, remember we had data we didn't have player just keep in mind fire client 82 00:05:55,360 --> 00:06:02,750 this says where where we're going to go to and this is the first parameter that gets passed over on 83 00:06:02,750 --> 00:06:03,920 the client side. 84 00:06:03,920 --> 00:06:05,420 So that's the data. 85 00:06:05,420 --> 00:06:09,230 If you remember that if you don't, it's understandable. 86 00:06:09,230 --> 00:06:12,050 We did a lot, but you can go poking around in there. 87 00:06:12,050 --> 00:06:17,950 So this here fires when the client, the player hits the buy button, right? 88 00:06:17,990 --> 00:06:22,970 And then it sends a remote event back to the server, back to this activate shop script. 89 00:06:22,970 --> 00:06:25,730 And we have a player, we have an item, we have a price. 90 00:06:25,730 --> 00:06:28,700 But we also started passing in the property type, right? 91 00:06:28,700 --> 00:06:37,910 We got prop type and when we did our tools, we went to replicated storage, checked first. 92 00:06:38,690 --> 00:06:40,250 It's not in replicated storage, right? 93 00:06:40,250 --> 00:06:41,650 We put it in server storage. 94 00:06:41,660 --> 00:06:47,150 So this if statement is not going to work because we're not actually checking. 95 00:06:47,850 --> 00:06:53,930 And we can't put it in our backpack, whatever it was, because it's not a tool, it's a piece of property. 96 00:06:53,940 --> 00:06:55,020 So let's get rid of that. 97 00:06:55,020 --> 00:07:02,100 If statement, let's get rid of this end because that was the end for the if and I'll format my document. 98 00:07:02,760 --> 00:07:03,630 There we go. 99 00:07:03,660 --> 00:07:06,720 We're going to add a few lines here, though. 100 00:07:07,620 --> 00:07:16,410 We're going to use the property manager to add property item to the world. 101 00:07:16,410 --> 00:07:16,650 Right. 102 00:07:16,650 --> 00:07:18,630 We're not putting it on the character anymore. 103 00:07:18,750 --> 00:07:22,530 The character will own it, but we're putting it in the world on his lot. 104 00:07:22,530 --> 00:07:28,230 So we'll just say player and then that's the item that's going to be like the cabin or the fence. 105 00:07:28,230 --> 00:07:32,190 And then we got to add it to their inventory. 106 00:07:32,190 --> 00:07:37,260 So add item to player's inventory so that it saves off. 107 00:07:37,290 --> 00:07:41,890 We'll get the player, we'll get the prop type, what do we call that? 108 00:07:42,150 --> 00:07:43,350 IntelliSense kills me. 109 00:07:43,350 --> 00:07:45,150 Prop type right here. 110 00:07:46,530 --> 00:07:46,950 Right. 111 00:07:46,950 --> 00:07:48,730 It's a key value pair. 112 00:07:48,760 --> 00:07:50,080 That's how we're saving it. 113 00:07:50,080 --> 00:07:52,420 So that's going to be like house or fence. 114 00:07:52,420 --> 00:07:56,830 And then this is going to be the item that's going to be cabin or fence. 115 00:07:56,830 --> 00:07:58,720 We should have made it like wood fence, right? 116 00:07:59,260 --> 00:07:59,560 All right. 117 00:07:59,560 --> 00:08:00,700 That's looking good. 118 00:08:01,510 --> 00:08:08,440 Now, if we test it, we should see the property plop onto the lot when we buy it. 119 00:08:08,470 --> 00:08:12,430 The downside is we still haven't done the equip player with the property. 120 00:08:12,430 --> 00:08:16,840 So when they go back in the game, you're not going to have the house available yet, but it's going 121 00:08:16,840 --> 00:08:17,290 to be easy. 122 00:08:17,290 --> 00:08:19,750 Fix So let's get the cabin. 123 00:08:21,860 --> 00:08:22,790 Buy a house. 124 00:08:22,790 --> 00:08:23,870 Oh, look at that. 125 00:08:23,870 --> 00:08:26,360 And then I think we have enough for the fence, too, right? 126 00:08:27,140 --> 00:08:27,830 That's. 127 00:08:29,270 --> 00:08:30,350 You bought the fence. 128 00:08:30,360 --> 00:08:32,910 Let's check for errors in the output window. 129 00:08:33,940 --> 00:08:34,910 That's looking good. 130 00:08:34,930 --> 00:08:36,040 Here's our data, too. 131 00:08:36,070 --> 00:08:37,690 That's being saved off. 132 00:08:37,690 --> 00:08:39,340 So I open that up here. 133 00:08:39,340 --> 00:08:41,140 Let's make this bigger so we can see it. 134 00:08:41,850 --> 00:08:47,460 We want to make sure that the data is going to the data store being saved off. 135 00:08:47,490 --> 00:08:48,960 Yeah, we got the house. 136 00:08:48,990 --> 00:08:51,240 We got a cabin down here. 137 00:08:53,280 --> 00:08:55,340 We got the cabin and the fence. 138 00:08:55,350 --> 00:08:56,850 That's looking pretty good. 139 00:08:57,900 --> 00:09:04,050 Now let's go ahead and equip the player when they enter the game, because now if you enter the game, 140 00:09:04,050 --> 00:09:05,690 you're not going to get that house. 141 00:09:05,700 --> 00:09:07,440 You're going to have it in your data. 142 00:09:07,470 --> 00:09:09,330 It's just not going to be visible. 143 00:09:10,100 --> 00:09:11,480 Let's take a look real quick. 144 00:09:13,830 --> 00:09:14,310 Right. 145 00:09:14,310 --> 00:09:15,450 It's not there yet. 146 00:09:15,480 --> 00:09:17,110 We have to add it to equip player. 147 00:09:17,130 --> 00:09:18,540 Let's do that now. 148 00:09:18,840 --> 00:09:20,510 I am in my property manager. 149 00:09:20,520 --> 00:09:22,580 This is under server script service. 150 00:09:22,590 --> 00:09:29,760 We're going to scroll down to equip player and we're already giving them the lot and setting the beam. 151 00:09:29,760 --> 00:09:32,490 But we need to check for the house and the fence now. 152 00:09:32,490 --> 00:09:40,590 So I'm going to say if property for the player, we already know that it exists because we checked that 153 00:09:40,590 --> 00:09:44,400 here, we checked it for the lot, but now let's check it for the house. 154 00:09:44,400 --> 00:09:53,730 So if house then prop manager add property item, right? 155 00:09:53,730 --> 00:09:56,610 Just like when we bought it, we're going to pass in the player. 156 00:09:56,610 --> 00:10:07,230 We're going to pass in the property for the player and we're going to use the house key, which is house. 157 00:10:07,230 --> 00:10:09,690 And then it should say cabin because we have it. 158 00:10:09,720 --> 00:10:14,950 We only have a cabin and we're going to do the exact same thing for the fence, right? 159 00:10:14,950 --> 00:10:18,760 Control C Let's scroll this up a little bit. 160 00:10:18,760 --> 00:10:29,800 Control V, we're going to change this to fence and we're going to change this to fence, and now we're 161 00:10:29,800 --> 00:10:30,940 going to play it. 162 00:10:30,940 --> 00:10:35,410 And we should see our house when we enter the game because it did save off to the data store when we 163 00:10:35,410 --> 00:10:37,750 were checking it last when we bought them. 164 00:10:37,750 --> 00:10:39,550 We're going to have to check this. 165 00:10:40,260 --> 00:10:41,260 Oh, look at that. 166 00:10:41,260 --> 00:10:43,720 We're going to have to check this with the test server, too. 167 00:10:43,720 --> 00:10:45,610 And our beam shuts off. 168 00:10:45,730 --> 00:10:47,120 Cool. 169 00:10:47,470 --> 00:10:49,540 And there we go in our house. 170 00:10:50,670 --> 00:10:51,510 I was pretty good. 171 00:10:51,510 --> 00:10:52,350 I like it.